{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cost = 40\n",
    "# 10 < cost < 50的等价表达式\n",
    "(10 < cost) and (cost < 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用int()将小数转换成整数，结果是向上取整数还是向下取整\n",
    "int(3.4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入年份：1994\n",
      "1994不是闰年\n"
     ]
    }
   ],
   "source": [
    "# 判定两份是否为闰年\n",
    "# 能够被4整除的年份\n",
    "year = input(\"请输入年份：\")\n",
    "\n",
    "# 先判断输入的是不是数字\n",
    "if year.isdigit():\n",
    "    year = int(year)\n",
    "    \n",
    "    if year % 4 == 0:\n",
    "        print(str(year) + \"是闰年\")\n",
    "    else:\n",
    "        print(str(year) + \"不是闰年\")\n",
    "else:\n",
    "    print(\"请输入年份\")\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给用户三次机会，猜想程序生成的一个数字A,每次用户猜想过后提示数字是否正确以及用户输入数字是大于A还是小于A，当机会用尽后提示用户已经输掉了游戏"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入数字：50\n",
      "你输入的数太大了\n",
      "请输入数字：25\n",
      "你输入的数太大了\n",
      "请输入数字：12\n",
      "你输入的数太小了\n",
      "请输入数字：18\n",
      "你输入的数太大了\n",
      "请输入数字：15\n",
      "你输入的数太小了\n",
      "请输入数字：16\n",
      "你猜对了\n",
      "你的机会用完了\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "secert = random.randint(1, 100) # 计算机生成一个随机数\n",
    "times = 6 # 初始化用户的次数是3次\n",
    "\n",
    "while times:\n",
    "    num = input(\"请输入数字：\")\n",
    "    if num.isdigit():\n",
    "        tmp = int(num)\n",
    "        if tmp == secert:\n",
    "            print(\"你猜对了\")\n",
    "            break\n",
    "        elif tmp < secert:\n",
    "            print(\"你输入的数太小了\")\n",
    "            times = times - 1\n",
    "        else:\n",
    "            print(\"你输入的数太大了\")\n",
    "            times = times - 1\n",
    "    else:\n",
    "        print(\"请你输入数字！！！\")\n",
    "print(\"你的机会用完了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
